package com.foreveross.chameleon.task;

import java.util.Map;
import java.util.Set;

import org.apache.http.Header;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.foreveross.chameleon.ModuleManager;
import com.foreveross.chameleon.activity.MainActivity;
import com.foreveross.chameleon.config.ChameleonConfig;
import com.foreveross.chameleon.listener.AsyncTaskListener;
import com.foreveross.chameleon.model.ApplicationInfo;
import com.foreveross.chameleon.model.ModuleInfo;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;

/**
 * @descrption module update task
 * @author zhouzhineng
 *
 */
public class ModuleSyncUpdateTask {

	private final String TAG = "ModuleSyncUpdateTask";
	protected Context mContext;
	protected AsyncTaskListener mAsyncTaskListener;
	
	public ModuleSyncUpdateTask(Context context,AsyncTaskListener asyncTaskListener) {
		mContext = context;
		mAsyncTaskListener = asyncTaskListener;
	}
	
	public void exec() {
		AsyncHttpClient httpClient = new AsyncHttpClient();
		httpClient.addHeader("User-Agent", "Chameleon");
		httpClient.get(ChameleonConfig.MODULE_SYNC_URL,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int code, Header[] header, byte[] msg) {
						// TODO Auto-generated method stub
						String result = new String(msg);
						mAsyncTaskListener.onSucc(result);				
					}

					@Override
					public void onFailure(int code, Header[] header,
							byte[] msg, Throwable thrw) {
						// TODO Auto-generated method stub
						mAsyncTaskListener.onFail(code);
					}
				});
	}
	

	

	
}
